@extends('layouts.tuceng')

<style type="text/css">
    body, html{width: 100%;height: 100%;margin:0;font-family:"微软雅黑";}
    #allmap{height:100%;width:100%;}
    #r-result{width:100%; font-size:14px;}
    .anchorBL{display:none;}
    #left-panel{position: absolute;left: 20px;top: 20px;overflow: hidden;pointer-events: none;width:383px;z-index:2;}
	#searchbox{border-radius: 2px;width: 382px;position: relative;z-index: 5;}
	#searchbox-container{position: relative;z-index: 2;pointer-events: auto;width: 325px;background-color: #fff;padding: 5px 15px;
	float: left;box-sizing: border-box;box-shadow: 1px 2px 1px rgba(0,0,0,.15);}
	#searchbox-container .searchbox-content-common{box-sizing: border-box;border: 0;
	padding: 9px 0;border-left: 10px solid transparent;border-right: 1px solid transparent;
	line-height: 20px;font-size: 16px;height: 38px;color: #333;position: relative;border-radius: 2px 0 0 2px;width: 286px;float: left;outline:0;}
	.searchbox-content-button{box-sizing: border-box;float: left;height: 38px;width: 39px;
	cursor: pointer;position: relative;background: #fff url(http://nb.yntosite.com/images/searchbox_d.png) no-repeat center;}
	#search-button{cursor: pointer;position: absolute;width: 57px;height: 38px;top: 0;
	background:url(http://nb.yntosite.com/images/searchbox_f.png) no-repeat center #3385ff;border:0;outline:0;}
	#cards-level1{width: 325px;position: relative;z-index:1000;top:8px;padding: 0;margin: 0;overflow: hidden;}
	.cardlist .card{pointer-events: auto;width: 100%;margin: 0;box-sizing: border-box;cursor: pointer;
	padding: 10px;background: #fff;box-shadow: 1px 2px 1px rgba(0,0,0,.15);overflow: auto;
	overflow-x: hidden;position: relative;border-radius: 2px;z-index: 100;list-style: none;}
	.cf{zoom: 1;padding: 10px;overflow: hidden;}
	.cf:hover{background-color: #f2f2f2;}
	.cf .col-l{float: left;width: 200px;}
	.cf .row{padding: 5px 0;line-height: 1.2;font-size: 12px;}
	.cf .name{white-space: nowrap;overflow: hidden;text-overflow: ellipsis;}
	.col-r{float: right;width: 88px;text-align: right;padding-top: 5px;}
	.col-r img{height:56px;}
</style>

@section('content')
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=DA98282be2425338a75f31de5640f5be"></script>
    <div id="shili_tb" class="easyui-window" closed="true" style="overflow: hidden;">
		<div id="taby" class="easyui-tabs" border="false" style="width:100%;height:auto;"></div>
    </div>
    <div class="content">
        <div style="border-left: 1px solid #cccccc;">
        	<div id="left-panel">
		    	<div id="searchbox">
		    		<div id="searchbox-container">
			    		<h3>重点企业列表</h3>
			    	</div>
		    	</div>
		    	<ul id="cards-level1" class="cardlist" >
		    		<li class="card animated-card">
		    			<div class="poi-wrapper">

							<!--<div class="cf" onclick="deletePoint(1)">
								<div class="col-l">
									<div class="row name">
										公司名：沙市轻轻工机械有限公司
									</div>
									<div class="row">法人名称：张三</div>
									<div class="row tel">联系方式：1597522347</div>
								</div>
								<div class="col-r"><img src="http://nb.yntosite.com/upload/qiye/2017-08-22/90ef1928534dbdf9d8f4a122335f348d5.jpg"></div>
							</div>-->

		    			</div>
		    		</li>
		    	</ul>
		    </div>
        	{{--<span id="lastinfo" style="display: none">{{$lasjson}}</span>--}}
        	<div id="allmap"></div>
        </div>
    </div>
    <script type="text/javascript" src="{{ URL::asset('/') }}js/weizhi.js"></script>
    <script type="text/javascript">
    	//搜索框列表
    	$(function(){
	    	$("#left-panel").hide();
    	});
    	(function(){
		    window.onresize=function(){
		      	var h=$(window).height();
		      	$('.card').css('height',(h-300)+'px');
		    }
	    })();
		$(function(){
			var h=$(window).height();
	       $('.card').css('height',(h-300)+'px');
		})
    	//加载tab
    	function addTab(title, url){
			if ($('#taby').tabs('exists', title)){
				$('#taby').tabs('select', title);
			} else {
				var content = '<iframe scrolling="auto" frameborder="0"  src="'+url+'" style="width:100%;height:100%;"></iframe>';
				$('#taby').tabs('add',{
					title:title,
					content:content,
					closable:false
				});
			}
		}

        function changesearch() {
            var keywords = $('#keywords').val();

            if (!keywords) {
                alert('名称不能为空');
                return false;
            }

            $('#search_form').submit();
        }

        // 百度地图API功能
        map = new BMap.Map("allmap",{enableMapClick:false});
        map.centerAndZoom(new BMap.Point(112.244594,30.341526), 15);

        //选择城市
        map.enableScrollWheelZoom();
        map.enableInertialDragging();
        map.enableContinuousZoom();
        var size = new BMap.Size(10, 20);
        /*map.addControl(new BMap.CityListControl({
            anchor: BMAP_ANCHOR_TOP_LEFT,
            offset: size,
        }));*/


        function getBoundary(city_id){
			var bdary = new BMap.Boundary();
			bdary.get(city_id, function(rs){       //获取行政区域
				map.clearOverlays();        //清除地图覆盖物
//				points_info();
				getdata(main_id);
				var count = rs.boundaries.length; //行政区域的点有多少个
				if (count === 0) {
					alert('未能获取当前输入行政区域');
					return ;
				}
	          	var pointArray = [];
				for (var i = 0; i < count; i++) {
					var ply = new BMap.Polygon(rs.boundaries[i], {strokeWeight: 2, strokeColor: "#ff0000", fillColor:"rgba(0,0,0,0)"}); //建立多边形覆盖物
					map.addOverlay(ply);  //添加覆盖物
					pointArray = pointArray.concat(ply.getPath());
				}
				map.setViewport(pointArray);    //调整视野
			});
		}
		var main_id = 0;
		function load_city_data_from_menu(id){
			main_id = id;
			map.clearOverlays();        //清除地图覆盖物
			//城市名	
			$.ajax({
				type:"POST",
				url:"{{url('admin/Mapapi/index')}}",
				data: {'id':id, '_token':'{{csrf_token()}}'},
				async:true,
				success:function(data){
					var obj = jQuery.parseJSON(data)
					console.log(obj);
					getBoundary(obj.newarea);
				}
			});
			//当前点击城市的搜索列表
			$.ajax({
				type:"POST",
				url:"{{url('admin/Mainapi/index')}}",
				data: {'id':id, '_token':'{{csrf_token()}}'},
				async:true,
				success:function(data){
					var obj = jQuery.parseJSON(data)
					console.log(obj);
					if(obj.length == 0){
						$("#left-panel").hide();
						$(".poi-wrapper").html('');
					}else{
						$("#left-panel").show();
						$(".poi-wrapper").html(obj);
					}
				}
			});
		}
		function load_area_data_from_menu(id){
			main_id = id;
			map.clearOverlays();        //清除地图覆盖物
			//城市名			
			$.ajax({
				type:"POST",
				url:"{{url('admin/Mapapi/index')}}",
				data: {'id':id, '_token':'{{csrf_token()}}'},
				async:true,
				success:function(data){
					var obj = jQuery.parseJSON(data)
					console.log(obj);
					getBoundary(obj.newarea);
				}
			});
			//当前点击城市的搜索列表
			$.ajax({
				type:"POST",
				url:"{{url('admin/Mainapi/index')}}",
				data: {'id':id, '_token':'{{csrf_token()}}'},
				async:true,
				success:function(data){
					var obj = jQuery.parseJSON(data)
					console.log(obj);
					if(obj.length == 0){
						$("#left-panel").hide();
						$(".poi-wrapper").html('');
					}else{
						$("#left-panel").show();
						$(".poi-wrapper").html(obj);
					}
				}
			});
		}


		 var shuz = fb1();
     // /home/www/jingzhouneibao/app/Http/Controllers/Admin
     // /home/www/jingzhouneibao/resources/views/admin/units
		function go(id){
			$('#shili_tb').window({
				title: "查看",
				href:"{{url('admin/units/tab2')}}"+"/"+id+"",
			    width:shuz[0],
				height:shuz[1],
				top:shuz[2],
				left:shuz[3],
				modal: true,
				closed: false,
				minimizable:false,
			});
		}
		var data_info = [];
		//滚轮事件判断缩放级别
		/*$("#allmap").on("mousewheel DOMMouseScroll", function (e) {

			var delta = (e.originalEvent.wheelDelta && (e.originalEvent.wheelDelta > 0 ? 1 : -1)) ||  // chrome & ie
						(e.originalEvent.detail && (e.originalEvent.detail > 0 ? -1 : 1));           // firefox
			console.log(map.getZoom())
			data_info = [];
			data_info2 = [];
			var flag = true;
			if(map.getZoom() >= 14){
				if(flag){
					console.log("main_id");
					console.log(main_id);
					if(main_id == 0){
						map.clearOverlays();        //清除地图覆盖物
						points_info();
					}else{
						map.clearOverlays();        //清除地图覆盖物
						getdata(main_id);
					}
					flag = false;
				}
			}else{
				map.clearOverlays();        //清除地图覆盖物
				flag = true;
			}
		});*/
		
		//点击列表，在地图点显示
		function deletePoint(i){
			map.setZoom(16);
			var allOverlay = map.getOverlays();//获取所有点覆盖物
			console.log(allOverlay);
			allOverlay[i].setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
			map.panTo(new BMap.Point(allOverlay[i].point.lng,allOverlay[i].point.lat));//跳转至当前列表选中的点
			setTimeout(function(){
				allOverlay[i].setAnimation(null); //取消跳动的动画
			},3000)
		}
		//非重点
		function fzd(fzddata){
			//非重点
					var points = [];  // 添加海量点数据
			        for (var i = 0; i < fzddata.length; i++) {
			          points.push(new BMap.Point(fzddata[i][0], fzddata[i][1]));
			        }
			        var options = {
			            size: BMAP_POINT_SIZE_SMALL,
			            shape: BMAP_POINT_SHAPE_CIRCLE,
			            color: '#66ccff'
			        }
			        var pointCollection = new BMap.PointCollection(points, options); // 初始化PointCollection
			        pointCollection.addEventListener('click', function (e) {
						var conte = "";
				        //关于自定义信息 修改json [[经度,维度,1,名称,地址,电话]]
				        //循环查出值
				        for (var i = 0; i < fzddata.length; i++) {
					        points.push(new BMap.Point(fzddata[i][0],fzddata[i][1]));
					        if(fzddata[i][0]==e.point.lng&&fzddata[i][1]==e.point.lat){//经度==点击的,维度
								conte = fzddata[i][2];
						        break;
					        }
				        }
				        var point = new BMap.Point(e.point.lng, e.point.lat);
				        var opts = {
					        width: 300, // 信息窗口宽度
					        height: 190, // 信息窗口高度
					        title:"", // 信息窗口标题
					        enableMessage: true,//设置允许信息窗发送短息
				        }
				        var infowindow = new BMap.InfoWindow(conte, opts);
				        map.openInfoWindow(infowindow, point);
			        });
			        map.addOverlay(pointCollection);  // 添加Overlay覆盖物
		}
		//重点
		function zd(zddata){
				var opts = {
	                width: 300, // 信息窗口宽度
	                height: 190, // 信息窗口高度
	                title: "", // 信息窗口标题
	                enableMessage: true//设置允许信息窗发送短息
	            };


	            for (var i = 0; i < zddata.length; i++) {

	                var content = zddata[i][2];

	                var marker = new BMap.Point(zddata[i][0], zddata[i][1]);

					var myIcon = new BMap.Icon(zddata[i][5], new BMap.Size(32,32));
	                /*if ( data_info[i][4] == 1) {
	                    var myIcon = new BMap.Icon("{{ URL::asset('/') }}images/hfangzi.png", new BMap.Size(50,50));
	                }else{
	                    var myIcon = new BMap.Icon("{{ URL::asset('/') }}images/fangzi.png", new BMap.Size(50,50));
	                }*/

	                var marker2 = new BMap.Marker(marker,{icon:myIcon});  // 创建标注

	                map.addOverlay(marker2);               // 将标注添加到地图中


	                addClickHandler(content, marker2);

	            }
	            function addClickHandler(content, marker) {
	                marker.addEventListener("click", function (e) {
	                        openInfo(content, e)
	                    }
	                );
	            }
	            function openInfo(content, e){
	                var p = e.target;
	                var point = new BMap.Point(p.getPosition().lng, p.getPosition().lat);
	                var infoWindow = new BMap.InfoWindow(content, opts);  // 创建信息窗口对象


	                map.openInfoWindow(infoWindow, point); //开启信息窗口
	                 //图片加载完毕重绘infowindow
	                //document.getElementById('imgDemo').onload = function (){
	                   //infoWindow.redraw();   //防止在网速较慢，图片未加载时，生成的信息框高度比图片的总高度小，导致图片部分被隐藏
	                //}
	                 $("#imgDemo").load(function(){
	                 	infoWindow.redraw()//防止在网速较慢，图片未加载时，生成的信息框高度比图片的总高度小，导致图片部分被隐藏
	                 })

	            }
		}
		
		function getdata(id){
			$.ajax({
				type:"POST",
				url:"{{url('admin/units/get_units_list')}}",
				data: {'id':id, '_token':'{{csrf_token()}}'},
				async:true,
				success:function(data){
//					var obj = jQuery.parseJSON(data)
					var obj = data;
					console.log(obj.feizhongdian);//非重点
					console.log(obj.zhongdian);//重点
					var feizhongdian = obj.feizhongdian;
					var zhongdian = obj.zhongdian;
					fzd(feizhongdian);
					zd(zhongdian);
				}
			});
		}
		points_info();
		function points_info(){
			//非重点
	        $.get("get_units",function(data,status){
	            data_info = data;
	            console.log("data_info");
	            console.log(data_info);
	            var points = [];  // 添加海量点数据
		        for (var i = 0; i < data_info.length; i++) {
		          points.push(new BMap.Point(data_info[i][0], data_info[i][1]));
		        }
		        var options = {
		            size: BMAP_POINT_SIZE_SMALL,
		            shape: BMAP_POINT_SHAPE_CIRCLE,
		            color: '#66ccff'
		        }
		        var pointCollection = new BMap.PointCollection(points, options); // 初始化PointCollection
		        pointCollection.addEventListener('click', function (e) {
					var conte = "";
			        //关于自定义信息 修改json [[经度,维度,1,名称,地址,电话]]
			        //循环查出值
			        for (var i = 0; i < data_info.length; i++) {
				        points.push(new BMap.Point(data_info[i][0],data_info[i][1]));
				        if(data_info[i][0]==e.point.lng&&data_info[i][1]==e.point.lat){//经度==点击的,维度
							conte = data_info[i][2];
					        break;
				        }
			        }
			        var point = new BMap.Point(e.point.lng, e.point.lat);
			        var opts = {
				        width: 300, // 信息窗口宽度
				        height: 190, // 信息窗口高度
				        title:"", // 信息窗口标题
				        enableMessage: true,//设置允许信息窗发送短息
			        }
			        var infowindow = new BMap.InfoWindow(conte, opts);
			        map.openInfoWindow(infowindow, point);
		        });
		        map.addOverlay(pointCollection);  // 添加Overlay覆盖物
	        });
	        var data_info2 = [];
	        //重点
			$.get("get_zdunits",function(data,status){
				data_info2 = data;
				console.log("data_info2");
				console.log(data_info2);
	            var opts = {
	                width: 300, // 信息窗口宽度
	                height: 190, // 信息窗口高度
	                title: "", // 信息窗口标题
	                enableMessage: true//设置允许信息窗发送短息
	            };


	            for (var i = 0; i < data_info2.length; i++) {

	                var content = data_info2[i][2];

	                var marker = new BMap.Point(data_info2[i][0], data_info2[i][1]);

					var myIcon = new BMap.Icon(data_info2[i][5], new BMap.Size(32,32));
	                /*if ( data_info[i][4] == 1) {
	                    var myIcon = new BMap.Icon("{{ URL::asset('/') }}images/hfangzi.png", new BMap.Size(50,50));
	                }else{
	                    var myIcon = new BMap.Icon("{{ URL::asset('/') }}images/fangzi.png", new BMap.Size(50,50));
	                }*/

	                var marker2 = new BMap.Marker(marker,{icon:myIcon});  // 创建标注

	                map.addOverlay(marker2);               // 将标注添加到地图中


	                addClickHandler(content, marker2);

	            }
	            function addClickHandler(content, marker) {
	                marker.addEventListener("click", function (e) {
	                        openInfo(content, e)
	                    }
	                );
	            }
	            function openInfo(content, e){
	                var p = e.target;
	                var point = new BMap.Point(p.getPosition().lng, p.getPosition().lat);
	                var infoWindow = new BMap.InfoWindow(content, opts);  // 创建信息窗口对象


	                map.openInfoWindow(infoWindow, point); //开启信息窗口
	                 //图片加载完毕重绘infowindow
	                //document.getElementById('imgDemo').onload = function (){
	                   //infoWindow.redraw();   //防止在网速较慢，图片未加载时，生成的信息框高度比图片的总高度小，导致图片部分被隐藏
	                //}
	                 $("#imgDemo").load(function(){
	                 	infoWindow.redraw()//防止在网速较慢，图片未加载时，生成的信息框高度比图片的总高度小，导致图片部分被隐藏
	                 })

	            }

							


			});
        }


    </script>
@stop

